
require 'appwiki/base/base_route.rb'
require 'appwiki/user/user.rb'

class UserRoute < BaseRoute
  def self.get_handlerpath(request,response,requestpath)
    # where to look for the controller.rb and .rhtml files
    handlerpath = nil
    # where to fetch media assets (everything excepting controller.rb and .rhtml files)
    workingpath = nil
    # /[username]/[method name]
    if !handlerpath && requestpath.length > 1
      subject = User.find_by_login(requestpath[1])
      if subject
        workingpath = requestpath[0..1]
        handlerpath = requestpath[0..0] + ["user"]
      end
    end
    # when /user/* (used for not on a specific entity but to see all or create )
    # TODO we need a system to reserve file paths even if user objects overlap
    if !handlerpath && requestpath.length > 1 && requestpath[1] == "user"
      workingpath = requestpath[0..1]
      handlerpath = requestpath[0..1]
    end

    # return success or failure
    return handlerpath,workingpath,requestpath
  end
end
